package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.response.DeviceVersionListResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 *
 * 网络请求  获取版本信息列表
 * Created by lifeng on 2018/7/2.
 */

public class GetDeviceVersionListRequest extends Request<DeviceVersionListResponse> {
    private String efairydevicecompanycode_id;//企业代码编号
    private String efairydeviceusagecode_id;//用途代码编号
    private String lastId;

    public GetDeviceVersionListRequest(String deviceCompanyCodeId,String DeviceUsageCodeId,String lastId,Response.Listener<DeviceVersionListResponse> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/device_version_list"), listener);
        this.efairydevicecompanycode_id = deviceCompanyCodeId;
        this.efairydeviceusagecode_id = DeviceUsageCodeId;
        this.lastId = lastId;
    }




    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());//设备编号
        addParam("access_token", CacheManager.getAccessToken());//令牌
        addParam("efairydevicecompanycode_id", efairydevicecompanycode_id);//企业代码编号
        addParam("efairydeviceusagecode_id", efairydeviceusagecode_id);//用途代码编号
        addParam("last_id", lastId);
        addParam("size", "10");
        return super.getParams();
    }

    @Override
    protected DeviceVersionListResponse parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<DeviceVersionListResponse>() {
        }.getType());
    }

}
